using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using iBeauty.BusinessObjects;

namespace iBeauty.DAL
{
    public class PreferenceDAO
    {
        public PreferenceDAO()
        {
            DbProviderHelper.GetConnection();
        }
        public List<Preference> GetPreferences()
        {
            try
            {
                List<Preference> lstPreferences = new List<Preference>();
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[TerminalID],[CompanyName],[ShopCode],[ShopName],[Address],[Phone],[Fax],[Email],[Website],[Logo],[StartDate],[EndDate],[TaxRateIn],[RoundTypeIn],[TaxRateOut],[RoundTypeOut],[ExchangeRate ],[AccountId] FROM [Preference]", CommandType.Text);
                DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
                while (oDbDataReader.Read())
                {
                    Preference oPreference = new Preference();
                    oPreference.ID = Convert.ToString(oDbDataReader["ID"]);

                    if (oDbDataReader["CreateDate"] != DBNull.Value)
                        oPreference.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

                    if (oDbDataReader["ModifiedDate"] != DBNull.Value)
                        oPreference.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

                    if (oDbDataReader["TimeStamp"] != DBNull.Value)
                        oPreference.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

                    if (oDbDataReader["TerminalID"] != DBNull.Value)
                        oPreference.TerminalID = Convert.ToString(oDbDataReader["TerminalID"]);

                    if (oDbDataReader["CompanyName"] != DBNull.Value)
                        oPreference.CompanyName = Convert.ToString(oDbDataReader["CompanyName"]);

                    if (oDbDataReader["ShopCode"] != DBNull.Value)
                        oPreference.ShopCode = Convert.ToString(oDbDataReader["ShopCode"]);

                    if (oDbDataReader["ShopName"] != DBNull.Value)
                        oPreference.ShopName = Convert.ToString(oDbDataReader["ShopName"]);

                    if (oDbDataReader["Address"] != DBNull.Value)
                        oPreference.Address = Convert.ToString(oDbDataReader["Address"]);

                    if (oDbDataReader["Phone"] != DBNull.Value)
                        oPreference.Phone = Convert.ToString(oDbDataReader["Phone"]);

                    if (oDbDataReader["Fax"] != DBNull.Value)
                        oPreference.Fax = Convert.ToString(oDbDataReader["Fax"]);

                    if (oDbDataReader["Email"] != DBNull.Value)
                        oPreference.Email = Convert.ToString(oDbDataReader["Email"]);

                    if (oDbDataReader["Website"] != DBNull.Value)
                        oPreference.Website = Convert.ToString(oDbDataReader["Website"]);

                    if (oDbDataReader["Logo"] != DBNull.Value)
                        oPreference.Logo = (Byte[])(oDbDataReader["Logo"]);

                    if (oDbDataReader["StartDate"] != DBNull.Value)
                        oPreference.StartDate = Convert.ToDateTime(oDbDataReader["StartDate"]);

                    if (oDbDataReader["EndDate"] != DBNull.Value)
                        oPreference.EndDate = Convert.ToDateTime(oDbDataReader["EndDate"]);

                    if (oDbDataReader["TaxRateIn"] != DBNull.Value)
                        oPreference.TaxRateIn = Convert.ToDouble(oDbDataReader["TaxRateIn"]);

                    if (oDbDataReader["RoundTypeIn"] != DBNull.Value)
                        oPreference.RoundTypeIn = Convert.ToString(oDbDataReader["RoundTypeIn"]);

                    if (oDbDataReader["TaxRateOut"] != DBNull.Value)
                        oPreference.TaxRateOut = Convert.ToDouble(oDbDataReader["TaxRateOut"]);

                    if (oDbDataReader["RoundTypeOut"] != DBNull.Value)
                        oPreference.RoundTypeOut = Convert.ToString(oDbDataReader["RoundTypeOut"]);

                    if (oDbDataReader["ExchangeRate "] != DBNull.Value)
                        oPreference.ExchangeRate = Convert.ToDouble(oDbDataReader["ExchangeRate "]);

                    if (oDbDataReader["AccountId"] != DBNull.Value)
                        oPreference.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);
                    lstPreferences.Add(oPreference);
                }
                oDbDataReader.Close();
                return lstPreferences;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

        public DataTable LoadStoreName()
        {
            DataTable dataTable = new DataTable();
            DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ShopCode],[ShopName] FROM [Shop]", CommandType.Text);
            DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
            dataTable.Load(oDbDataReader);
            oDbDataReader.Close();
            return dataTable;

        }

        public Preference GetPreferences1()
        {
            try
            {
                Preference oPreference = new Preference();
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[TerminalID],[CompanyName],[ShopCode],[ShopName],[Address],[Phone],[Fax],[Email],[Website],[Logo],[StartDate],[EndDate],[TaxRateIn],[RoundTypeIn],[TaxRateOut],[RoundTypeOut],[ExchangeRate ],[AccountId] FROM [Preference]", CommandType.Text);
                DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
                while (oDbDataReader.Read())
                {

                    oPreference.ID = Convert.ToString(oDbDataReader["ID"]);

                    if (oDbDataReader["CreateDate"] != DBNull.Value)
                        oPreference.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

                    if (oDbDataReader["ModifiedDate"] != DBNull.Value)
                        oPreference.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

                    if (oDbDataReader["TimeStamp"] != DBNull.Value)
                        oPreference.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

                    if (oDbDataReader["TerminalID"] != DBNull.Value)
                        oPreference.TerminalID = Convert.ToString(oDbDataReader["TerminalID"]);

                    if (oDbDataReader["CompanyName"] != DBNull.Value)
                        oPreference.CompanyName = Convert.ToString(oDbDataReader["CompanyName"]);

                    if (oDbDataReader["ShopCode"] != DBNull.Value)
                        oPreference.ShopCode = Convert.ToString(oDbDataReader["ShopCode"]);

                    if (oDbDataReader["ShopName"] != DBNull.Value)
                        oPreference.ShopName = Convert.ToString(oDbDataReader["ShopName"]);

                    if (oDbDataReader["Address"] != DBNull.Value)
                        oPreference.Address = Convert.ToString(oDbDataReader["Address"]);

                    if (oDbDataReader["Phone"] != DBNull.Value)
                        oPreference.Phone = Convert.ToString(oDbDataReader["Phone"]);

                    if (oDbDataReader["Fax"] != DBNull.Value)
                        oPreference.Fax = Convert.ToString(oDbDataReader["Fax"]);

                    if (oDbDataReader["Email"] != DBNull.Value)
                        oPreference.Email = Convert.ToString(oDbDataReader["Email"]);

                    if (oDbDataReader["Website"] != DBNull.Value)
                        oPreference.Website = Convert.ToString(oDbDataReader["Website"]);

                    if (oDbDataReader["Logo"] != DBNull.Value)
                        oPreference.Logo = (Byte[])(oDbDataReader["Logo"]);

                    if (oDbDataReader["StartDate"] != DBNull.Value)
                        oPreference.StartDate = Convert.ToDateTime(oDbDataReader["StartDate"]);

                    if (oDbDataReader["EndDate"] != DBNull.Value)
                        oPreference.EndDate = Convert.ToDateTime(oDbDataReader["EndDate"]);

                    if (oDbDataReader["TaxRateIn"] != DBNull.Value)
                        oPreference.TaxRateIn = Convert.ToDouble(oDbDataReader["TaxRateIn"]);

                    if (oDbDataReader["RoundTypeIn"] != DBNull.Value)
                        oPreference.RoundTypeIn = Convert.ToString(oDbDataReader["RoundTypeIn"]);

                    if (oDbDataReader["TaxRateOut"] != DBNull.Value)
                        oPreference.TaxRateOut = Convert.ToDouble(oDbDataReader["TaxRateOut"]);

                    if (oDbDataReader["RoundTypeOut"] != DBNull.Value)
                        oPreference.RoundTypeOut = Convert.ToString(oDbDataReader["RoundTypeOut"]);

                    if (oDbDataReader["ExchangeRate "] != DBNull.Value)
                        oPreference.ExchangeRate = Convert.ToDouble(oDbDataReader["ExchangeRate "]);

                    if (oDbDataReader["AccountId"] != DBNull.Value)
                        oPreference.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);
                }
                oDbDataReader.Close();
                return oPreference;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public Preference GetPreference(string ID)
        {
            try
            {
                Preference oPreference = new Preference();
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("SELECT [ID],[CreateDate],[ModifiedDate],[TimeStamp],[TerminalID],[CompanyName],[ShopCode],[ShopName],[Address],[Phone],[Fax],[Email],[Website],[Logo],[StartDate],[EndDate],[TaxRateIn],[RoundTypeIn],[TaxRateOut],[RoundTypeOut],[ExchangeRate ],[AccountId] FROM [Preference] WHERE [ID]=@ID", CommandType.Text);
                oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID", DbType.String, ID));
                DbDataReader oDbDataReader = DbProviderHelper.ExecuteReader(oDbCommand);
                while (oDbDataReader.Read())
                {
                    oPreference.ID = Convert.ToString(oDbDataReader["ID"]);

                    if (oDbDataReader["CreateDate"] != DBNull.Value)
                        oPreference.CreateDate = Convert.ToDateTime(oDbDataReader["CreateDate"]);

                    if (oDbDataReader["ModifiedDate"] != DBNull.Value)
                        oPreference.ModifiedDate = Convert.ToDateTime(oDbDataReader["ModifiedDate"]);

                    if (oDbDataReader["TimeStamp"] != DBNull.Value)
                        oPreference.TimeStamp = Convert.ToDateTime(oDbDataReader["TimeStamp"]);

                    if (oDbDataReader["TerminalID"] != DBNull.Value)
                        oPreference.TerminalID = Convert.ToString(oDbDataReader["TerminalID"]);

                    if (oDbDataReader["CompanyName"] != DBNull.Value)
                        oPreference.CompanyName = Convert.ToString(oDbDataReader["CompanyName"]);

                    if (oDbDataReader["ShopCode"] != DBNull.Value)
                        oPreference.ShopCode = Convert.ToString(oDbDataReader["ShopCode"]);

                    if (oDbDataReader["ShopName"] != DBNull.Value)
                        oPreference.ShopName = Convert.ToString(oDbDataReader["ShopName"]);

                    if (oDbDataReader["Address"] != DBNull.Value)
                        oPreference.Address = Convert.ToString(oDbDataReader["Address"]);

                    if (oDbDataReader["Phone"] != DBNull.Value)
                        oPreference.Phone = Convert.ToString(oDbDataReader["Phone"]);

                    if (oDbDataReader["Fax"] != DBNull.Value)
                        oPreference.Fax = Convert.ToString(oDbDataReader["Fax"]);

                    if (oDbDataReader["Email"] != DBNull.Value)
                        oPreference.Email = Convert.ToString(oDbDataReader["Email"]);

                    if (oDbDataReader["Website"] != DBNull.Value)
                        oPreference.Website = Convert.ToString(oDbDataReader["Website"]);

                    if (oDbDataReader["Logo"] != DBNull.Value)
                        oPreference.Logo = (Byte[])(oDbDataReader["Logo"]);

                    if (oDbDataReader["StartDate"] != DBNull.Value)
                        oPreference.StartDate = Convert.ToDateTime(oDbDataReader["StartDate"]);

                    if (oDbDataReader["EndDate"] != DBNull.Value)
                        oPreference.EndDate = Convert.ToDateTime(oDbDataReader["EndDate"]);

                    if (oDbDataReader["TaxRateIn"] != DBNull.Value)
                        oPreference.TaxRateIn = Convert.ToDouble(oDbDataReader["TaxRateIn"]);

                    if (oDbDataReader["RoundTypeIn"] != DBNull.Value)
                        oPreference.RoundTypeIn = Convert.ToString(oDbDataReader["RoundTypeIn"]);

                    if (oDbDataReader["TaxRateOut"] != DBNull.Value)
                        oPreference.TaxRateOut = Convert.ToDouble(oDbDataReader["TaxRateOut"]);

                    if (oDbDataReader["RoundTypeOut"] != DBNull.Value)
                        oPreference.RoundTypeOut = Convert.ToString(oDbDataReader["RoundTypeOut"]);

                    if (oDbDataReader["ExchangeRate "] != DBNull.Value)
                        oPreference.ExchangeRate = Convert.ToDouble(oDbDataReader["ExchangeRate "]);

                    if (oDbDataReader["AccountId"] != DBNull.Value)
                        oPreference.AccountId = Convert.ToInt32(oDbDataReader["AccountId"]);
                }
                oDbDataReader.Close();
                return oPreference;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int AddPreference(string ID, DateTime? CreateDate, DateTime? ModifiedDate, DateTime? TimeStamp, string TerminalID, string CompanyName, string ShopCode, string ShopName, string Address, string Phone, string Fax, string Email, string Website, Byte[] Logo, DateTime? StartDate, DateTime? EndDate, Double? TaxRateIn, string RoundTypeIn, Double? TaxRateOut, string RoundTypeOut, Double? ExchangeRate, int? AccountId)
        {
            try
            {
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Preference]([CreateDate],[ModifiedDate],[TimeStamp],[TerminalID],[CompanyName],[ShopCode],[ShopName],[Address],[Phone],[Fax],[Email],[Website],[Logo],[StartDate],[EndDate],[TaxRateIn],[RoundTypeIn],[TaxRateOut],[RoundTypeOut],[ExchangeRate ],[AccountId])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@TerminalID,@CompanyName,@ShopCode,@ShopName,@Address,@Phone,@Fax,@Email,@Website,@Logo,@StartDate,@EndDate,@TaxRateIn,@RoundTypeIn,@TaxRateOut,@RoundTypeOut,@ExchangeRate ,@AccountId)", CommandType.Text);
                if (CreateDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate", DbType.DateTime, CreateDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate", DbType.DateTime, DBNull.Value));
                if (ModifiedDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate", DbType.DateTime, ModifiedDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate", DbType.DateTime, DBNull.Value));
                if (TimeStamp.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp", DbType.DateTime, TimeStamp));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp", DbType.DateTime, DBNull.Value));
                if (TerminalID != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TerminalID", DbType.String, TerminalID));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TerminalID", DbType.String, DBNull.Value));
                if (CompanyName != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName", DbType.String, CompanyName));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName", DbType.String, DBNull.Value));
                if (ShopCode != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopCode", DbType.String, ShopCode));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopCode", DbType.String, DBNull.Value));
                if (ShopName != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopName", DbType.String, ShopName));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopName", DbType.String, DBNull.Value));
                if (Address != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address", DbType.String, Address));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address", DbType.String, DBNull.Value));
                if (Phone != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone", DbType.String, Phone));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone", DbType.String, DBNull.Value));
                if (Fax != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax", DbType.String, Fax));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax", DbType.String, DBNull.Value));
                if (Email != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email", DbType.String, Email));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email", DbType.String, DBNull.Value));
                if (Website != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website", DbType.String, Website));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website", DbType.String, DBNull.Value));
                if (Logo != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Logo", DbType.Binary, Logo));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Logo", DbType.Binary, DBNull.Value));
                if (StartDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartDate", DbType.DateTime, StartDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartDate", DbType.DateTime, DBNull.Value));
                if (EndDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@EndDate", DbType.DateTime, EndDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@EndDate", DbType.DateTime, DBNull.Value));
                if (TaxRateIn.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateIn", DbType.Double, TaxRateIn));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateIn", DbType.Double, DBNull.Value));
                if (RoundTypeIn != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeIn", DbType.String, RoundTypeIn));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeIn", DbType.String, DBNull.Value));
                if (TaxRateOut.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateOut", DbType.Double, TaxRateOut));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateOut", DbType.Double, DBNull.Value));
                if (RoundTypeOut != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeOut", DbType.String, RoundTypeOut));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeOut", DbType.String, DBNull.Value));
                if (ExchangeRate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExchangeRate", DbType.Double, ExchangeRate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExchangeRate", DbType.Double, DBNull.Value));
                if (AccountId.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId", DbType.Int32, AccountId));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId", DbType.Int32, DBNull.Value));

                return DbProviderHelper.ExecuteNonQuery(oDbCommand);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int AddPreference(Preference oPreference)
        {
            try
            {
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("INSERT INTO [Preference]([CreateDate],[ModifiedDate],[TimeStamp],[TerminalID],[CompanyName],[ShopCode],[ShopName],[Address],[Phone],[Fax],[Email],[Website],[Logo],[StartDate],[EndDate],[TaxRateIn],[RoundTypeIn],[TaxRateOut],[RoundTypeOut],[ExchangeRate ],[AccountId])VALUES(@CreateDate,@ModifiedDate,@TimeStamp,@TerminalID,@CompanyName,@ShopCode,@ShopName,@Address,@Phone,@Fax,@Email,@Website,@Logo,@StartDate,@EndDate,@TaxRateIn,@RoundTypeIn,@TaxRateOut,@RoundTypeOut,@ExchangeRate ,@AccountId)", CommandType.Text);
                if (oPreference.CreateDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate", DbType.DateTime, oPreference.CreateDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate", DbType.DateTime, DBNull.Value));
                if (oPreference.ModifiedDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate", DbType.DateTime, oPreference.ModifiedDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate", DbType.DateTime, DBNull.Value));
                if (oPreference.TimeStamp.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp", DbType.DateTime, oPreference.TimeStamp));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp", DbType.DateTime, DBNull.Value));
                if (oPreference.TerminalID != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TerminalID", DbType.String, oPreference.TerminalID));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TerminalID", DbType.String, DBNull.Value));
                if (oPreference.CompanyName != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName", DbType.String, oPreference.CompanyName));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName", DbType.String, DBNull.Value));
                if (oPreference.ShopCode != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopCode", DbType.String, oPreference.ShopCode));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopCode", DbType.String, DBNull.Value));
                if (oPreference.ShopName != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopName", DbType.String, oPreference.ShopName));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopName", DbType.String, DBNull.Value));
                if (oPreference.Address != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address", DbType.String, oPreference.Address));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address", DbType.String, DBNull.Value));
                if (oPreference.Phone != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone", DbType.String, oPreference.Phone));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone", DbType.String, DBNull.Value));
                if (oPreference.Fax != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax", DbType.String, oPreference.Fax));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax", DbType.String, DBNull.Value));
                if (oPreference.Email != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email", DbType.String, oPreference.Email));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email", DbType.String, DBNull.Value));
                if (oPreference.Website != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website", DbType.String, oPreference.Website));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website", DbType.String, DBNull.Value));
                if (oPreference.Logo != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Logo", DbType.Binary, oPreference.Logo));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Logo", DbType.Binary, DBNull.Value));
                if (oPreference.StartDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartDate", DbType.DateTime, oPreference.StartDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartDate", DbType.DateTime, DBNull.Value));
                if (oPreference.EndDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@EndDate", DbType.DateTime, oPreference.EndDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@EndDate", DbType.DateTime, DBNull.Value));
                if (oPreference.TaxRateIn.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateIn", DbType.Double, oPreference.TaxRateIn));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateIn", DbType.Double, DBNull.Value));
                if (oPreference.RoundTypeIn != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeIn", DbType.String, oPreference.RoundTypeIn));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeIn", DbType.String, DBNull.Value));
                if (oPreference.TaxRateOut.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateOut", DbType.Double, oPreference.TaxRateOut));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateOut", DbType.Double, DBNull.Value));
                if (oPreference.RoundTypeOut != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeOut", DbType.String, oPreference.RoundTypeOut));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeOut", DbType.String, DBNull.Value));
                if (oPreference.ExchangeRate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExchangeRate", DbType.Double, oPreference.ExchangeRate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExchangeRate", DbType.Double, DBNull.Value));
                if (oPreference.AccountId.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId", DbType.Int32, oPreference.AccountId));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId", DbType.Int32, DBNull.Value));

                return DbProviderHelper.ExecuteNonQuery(oDbCommand);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int UpdatePreference(string ID, DateTime? CreateDate, DateTime? ModifiedDate, DateTime? TimeStamp, string TerminalID, string CompanyName, string ShopCode, string ShopName, string Address, string Phone, string Fax, string Email, string Website, Byte[] Logo, DateTime? StartDate, DateTime? EndDate, Double? TaxRateIn, string RoundTypeIn, Double? TaxRateOut, string RoundTypeOut, Double? ExchangeRate, int? AccountId)
        {

            try
            {
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Preference] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[TerminalID]=@TerminalID,[CompanyName]=@CompanyName,[ShopCode]=@ShopCode,[ShopName]=@ShopName,[Address]=@Address,[Phone]=@Phone,[Fax]=@Fax,[Email]=@Email,[Website]=@Website,[Logo]=@Logo,[StartDate]=@StartDate,[EndDate]=@EndDate,[TaxRateIn]=@TaxRateIn,[RoundTypeIn]=@RoundTypeIn,[TaxRateOut]=@TaxRateOut,[RoundTypeOut]=@RoundTypeOut,[ExchangeRate ]=@ExchangeRate ,[AccountId]=@AccountId WHERE [ID]=@ID", CommandType.Text);
                if (CreateDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate", DbType.DateTime, CreateDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate", DbType.DateTime, DBNull.Value));
                if (ModifiedDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate", DbType.DateTime, ModifiedDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate", DbType.DateTime, DBNull.Value));
                if (TimeStamp.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp", DbType.DateTime, TimeStamp));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp", DbType.DateTime, DBNull.Value));
                if (TerminalID != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TerminalID", DbType.String, TerminalID));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TerminalID", DbType.String, DBNull.Value));
                if (CompanyName != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName", DbType.String, CompanyName));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName", DbType.String, DBNull.Value));
                if (ShopCode != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopCode", DbType.String, ShopCode));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopCode", DbType.String, DBNull.Value));
                if (ShopName != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopName", DbType.String, ShopName));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopName", DbType.String, DBNull.Value));
                if (Address != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address", DbType.String, Address));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address", DbType.String, DBNull.Value));
                if (Phone != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone", DbType.String, Phone));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone", DbType.String, DBNull.Value));
                if (Fax != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax", DbType.String, Fax));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax", DbType.String, DBNull.Value));
                if (Email != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email", DbType.String, Email));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email", DbType.String, DBNull.Value));
                if (Website != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website", DbType.String, Website));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website", DbType.String, DBNull.Value));
                if (Logo != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Logo", DbType.Binary, Logo));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Logo", DbType.Binary, DBNull.Value));
                if (StartDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartDate", DbType.DateTime, StartDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartDate", DbType.DateTime, DBNull.Value));
                if (EndDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@EndDate", DbType.DateTime, EndDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@EndDate", DbType.DateTime, DBNull.Value));
                if (TaxRateIn.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateIn", DbType.Double, TaxRateIn));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateIn", DbType.Double, DBNull.Value));
                if (RoundTypeIn != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeIn", DbType.String, RoundTypeIn));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeIn", DbType.String, DBNull.Value));
                if (TaxRateOut.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateOut", DbType.Double, TaxRateOut));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateOut", DbType.Double, DBNull.Value));
                if (RoundTypeOut != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeOut", DbType.String, RoundTypeOut));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeOut", DbType.String, DBNull.Value));
                if (ExchangeRate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExchangeRate", DbType.Double, ExchangeRate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExchangeRate", DbType.Double, DBNull.Value));
                if (AccountId.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId", DbType.Int32, AccountId));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId", DbType.Int32, DBNull.Value));
                oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID", DbType.String, ID));
                return DbProviderHelper.ExecuteNonQuery(oDbCommand);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int UpdatePreference(Preference oPreference)
        {

            try
            {
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("UPDATE [Preference] SET [CreateDate]=@CreateDate,[ModifiedDate]=@ModifiedDate,[TimeStamp]=@TimeStamp,[TerminalID]=@TerminalID,[CompanyName]=@CompanyName,[ShopCode]=@ShopCode,[ShopName]=@ShopName,[Address]=@Address,[Phone]=@Phone,[Fax]=@Fax,[Email]=@Email,[Website]=@Website,[Logo]=@Logo,[StartDate]=@StartDate,[EndDate]=@EndDate,[TaxRateIn]=@TaxRateIn,[RoundTypeIn]=@RoundTypeIn,[TaxRateOut]=@TaxRateOut,[RoundTypeOut]=@RoundTypeOut,[ExchangeRate ]=@ExchangeRate ,[AccountId]=@AccountId WHERE [ID]=@ID", CommandType.Text);
                if (oPreference.CreateDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate", DbType.DateTime, oPreference.CreateDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CreateDate", DbType.DateTime, DBNull.Value));
                if (oPreference.ModifiedDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate", DbType.DateTime, oPreference.ModifiedDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ModifiedDate", DbType.DateTime, DBNull.Value));
                if (oPreference.TimeStamp.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp", DbType.DateTime, oPreference.TimeStamp));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TimeStamp", DbType.DateTime, DBNull.Value));
                if (oPreference.TerminalID != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TerminalID", DbType.String, oPreference.TerminalID));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TerminalID", DbType.String, DBNull.Value));
                if (oPreference.CompanyName != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName", DbType.String, oPreference.CompanyName));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@CompanyName", DbType.String, DBNull.Value));
                if (oPreference.ShopCode != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopCode", DbType.String, oPreference.ShopCode));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopCode", DbType.String, DBNull.Value));
                if (oPreference.ShopName != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopName", DbType.String, oPreference.ShopName));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ShopName", DbType.String, DBNull.Value));
                if (oPreference.Address != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address", DbType.String, oPreference.Address));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Address", DbType.String, DBNull.Value));
                if (oPreference.Phone != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone", DbType.String, oPreference.Phone));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Phone", DbType.String, DBNull.Value));
                if (oPreference.Fax != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax", DbType.String, oPreference.Fax));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Fax", DbType.String, DBNull.Value));
                if (oPreference.Email != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email", DbType.String, oPreference.Email));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Email", DbType.String, DBNull.Value));
                if (oPreference.Website != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website", DbType.String, oPreference.Website));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Website", DbType.String, DBNull.Value));
                if (oPreference.Logo != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Logo", DbType.Binary, oPreference.Logo));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@Logo", DbType.Binary, DBNull.Value));
                if (oPreference.StartDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartDate", DbType.DateTime, oPreference.StartDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@StartDate", DbType.DateTime, DBNull.Value));
                if (oPreference.EndDate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@EndDate", DbType.DateTime, oPreference.EndDate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@EndDate", DbType.DateTime, DBNull.Value));
                if (oPreference.TaxRateIn.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateIn", DbType.Double, oPreference.TaxRateIn));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateIn", DbType.Double, DBNull.Value));
                if (oPreference.RoundTypeIn != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeIn", DbType.String, oPreference.RoundTypeIn));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeIn", DbType.String, DBNull.Value));
                if (oPreference.TaxRateOut.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateOut", DbType.Double, oPreference.TaxRateOut));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@TaxRateOut", DbType.Double, DBNull.Value));
                if (oPreference.RoundTypeOut != null)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeOut", DbType.String, oPreference.RoundTypeOut));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@RoundTypeOut", DbType.String, DBNull.Value));
                if (oPreference.ExchangeRate.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExchangeRate", DbType.Double, oPreference.ExchangeRate));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ExchangeRate", DbType.Double, DBNull.Value));
                if (oPreference.AccountId.HasValue)
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId", DbType.Int32, oPreference.AccountId));
                else
                    oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@AccountId", DbType.Int32, DBNull.Value));
                oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID", DbType.String, oPreference.ID));
                return DbProviderHelper.ExecuteNonQuery(oDbCommand);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int RemovePreference(Preference oPreference)
        {

            try
            {
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Preference] WHERE [ID]=@ID", CommandType.Text);
                oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID", DbType.String, oPreference.ID));
                return DbProviderHelper.ExecuteNonQuery(oDbCommand);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        public int RemovePreference(string ID)
        {

            try
            {
                DbCommand oDbCommand = DbProviderHelper.CreateCommand("DELETE FROM [Preference] WHERE [ID]=@ID", CommandType.Text);
                oDbCommand.Parameters.Add(DbProviderHelper.CreateParameter("@ID", DbType.String, ID));
                return DbProviderHelper.ExecuteNonQuery(oDbCommand);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    }
}
